﻿Create FUNCTION [dbo].[UnusedIndexes]
	(@DatabaseID AS int)  RETURNS TABLE AS

RETURN

  SELECT    dt.TableName,
					ifd.IndexName,
					ifd.IndexType,
					CONVERT(DECIMAL(16, 1),ifd.IndexSize) AS IndexSize,
					ifd.Statistics_LastUpdatedDate,	
					ifd.IS_PK	,	
					ifd.Fragmentation,
					ifd.IndexScans
					
FROM         [Index] AS ifd INNER JOIN
             [Table] AS dt ON dt.TableID = ifd.TableID    
             
             where      ifd.IndexType = 'NONCLUSTERED INDEX'
             and ifd.IndexSeeks = 0             
                      
and   @DatabaseID = dt.DatabaseID